<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>商品信息</strong></div>
  <div class="body-content">
  	<form method="post" class="form-x" onsubmit="return check()" action="AlterGoods.do">  
  	   <div class="form-group">
        <div class="label">
          <label>商品编号：</label>
        </div>
        <div class="field">
        <input type="text" name="gid" value="${goods.gid}" readonly="true"/>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>商品名称：</label>
        </div>
        <div class="field">
          <span id="gname">${goods.gname}</span>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>图片：</label>
        </div>
        <div class="field">
          <input type="file" class="button bg-blue margin-left" id="gimage" style="float:left;">
          <div class="tipss">图片尺寸：500*500</div>
        </div>
      </div>     
        <div class="form-group">
          <div class="label">
            <label>商品分类：</label>
          </div>
          <div class="field">
          <span id="cid">${goods.cid}</span>
            <div class="tips"></div>
          </div>
        </div>
        <div class="form-group">
          <div class="label">
            <label>价格：</label>
          </div>
      	  <div class="field">
      	  <span id="gprice" value=5>${goods.gprice}</span>
            <div class="tips"></div>
          </div>
        </div>
         <div class="form-group">
          <div class="label">
            <label>库存：</label>
          </div>
      	<div class="field">
      	<span id="gstock">${goods.gstock}</span>
          <div class="tips"></div>
        </div>
        </div>

      <div class="form-group">
        <div class="label">
          <label>商品内容：</label>
        </div>
        <div class="field">
        <span id="content">${goods.content}</span>
          <div class="tips"></div>
        </div>
      </div>
      <div class="clear"></div>
      <div class="form-group">
        <div class="label">
          <label>上架时间：</label>
        </div>
        <div class="field">
        <span id="shelftime">${goods.shelftime}</span>
          <div class="tips"></div>
        </div>
      </div>
      <br></br>
      <div class="form-group">
        <div class="label">
          <label>品牌：</label>
        </div>
        <div class="field">
        <span id="brand">${goods.brand}</span>        
          <div class="tips"></div>
        </div>
      </div>
      		<br></br>
        <div id="button" class="button-group"><a  class="button border-main" onclick='changetotal()' href="javascript:void(0)"><span class="icon-edit"></span>修改</a> </div>
   </form>
  </div>
</div>
<script type="text/javascript">
function changetotal(){
	changebutton();
	changename();			//修改商品名称
	changecid();			//修改商品种类
	changeprice();			//修改商品价格
	changestock();			//修改商品库存
	changecontent();		//修改商品内容
	changeshelftime();		//修改上架时间
	changebrand();			//修改品牌
}
function changebutton(){
 var o = document.getElementById("button"); //定位id为button的位置
 o.innerHTML = "<button class='button bg-main icon-check-square-o' type='submit'> 保存</button>"
}
function changename(){//修改商品名称
 var o = document.getElementById("gname"); //定位id为name的位置
 var c = o.innerHTML;   //其原先的内容
 o.innerHTML = "<input type='text' class='input w50' name='gname' value='" + c + "'/>"
}
function changecid(){//修改商品种类
 var o = document.getElementById("cid");
 var c = o.innerHTML;
 o.innerHTML = "<select name='cid' class='input w50'><option value=''>请选择分类</option><option value='台式电脑'>台式电脑</option><option value='笔记本电脑'>笔记本电脑</option><option value='电脑硬件'>电脑硬件</option></select>"
}
function changeprice(){//修改商品价格
 var o = document.getElementById("gprice");
 var c = o.innerHTML;
 o.innerHTML = " <input type='text' class='input w50' id='price' name='gprice' value='" + c + "'/>"
}
function changestock(){//修改商品库存
 var o = document.getElementById("gstock");
 var c = o.innerHTML;
 o.innerHTML = "<input type='text' class='input w50' id='stock' name='gstock' value='" + c + "'/>"
}

function changecontent(){//修改商品内容
 var o = document.getElementById("content");
 var c = o.innerHTML;
 o.innerHTML = "<textarea name='content' class='input' style='height:450px; border:1px solid #ddd;'>" + c + "</textarea>"
}
function changeshelftime(){//修改上架时间
 var o = document.getElementById("shelftime");
 var c = o.innerHTML;
 o.innerHTML = "<input type='date' class='laydate-icon input w50' id='time' name='shelftime' style='padding:10px!important; height:auto!important;border:1px solid #ddd!important;' value='" + c + "'/>"
}
function changebrand(){//修改品牌
 var o = document.getElementById("brand");
 var c = o.innerHTML;
 o.innerHTML = "<input type='text' class='input w50' name='brand' value='" + c + "'/>"
}
function check(){
if((/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/).test(price.value))
	if(/^[1-9]\d*|0$/.test(stock.value))
		if(/^((((19|20)\d{2})-(0?[13-9]|1[012])-(0?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-31)|(((19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$/.test(time.value))
			return true;
		else{ 
				alert("上架时间不能为空！");
				return false;
		}
	else {
			alert("库存数量必须为数字！");
			return false;
		}
else {
		alert("商品价格必须为数字！");
		return false;
	} 
}
</script>
</body></html>